package com.hxiaoyi.cloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * GateWayConfig 配置类
 * @author 黄敬意
 * @date 2022-02-19 21:24
 **/
@Configuration
public class GateWayConfig {
    /**
     * 类似与ngibx的转发地址 访问http://127.0.0.1:9527/guonei就会转发到这个地址http://news.baidu.com/guonei
     * @param routeLocatorBuilder
     * @return routs
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder){
        RouteLocatorBuilder.Builder routs = routeLocatorBuilder.routes();
        routs.route("path_route_hxiaoyi",
                r -> r.path("/guonei")
                        .uri("http://news.baidu.com/guonei")).build();
        return routs.build();
    }

    /**
     * 类似与ngibx的转发地址 访问http://127.0.0.1:9527/guonei就会转发到这个地址http://news.baidu.com/guonei
     * @param routeLocatorBuilder
     * @return routs
     */
    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder routeLocatorBuilder){
        RouteLocatorBuilder.Builder routs = routeLocatorBuilder.routes();
        routs.route("path_route_hxiaoyi",
                r -> r.path("/guoji")
                        .uri("http://news.baidu.com/guoji")).build();
        return routs.build();
    }
}
